<?php

class Main_model extends CI_Model {


    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function set_masukan($data)
    {
		$this->db->insert('dn_feedback',$data);
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		return FALSE;
	}
	
	function set_lapor($data)
	{
		$this->db->insert('dn_report',$data);
		if($this->db->affected_rows() > 0)
		{
			return true;
		}
		return false;
	}
	
	function get_login($data)
	{
		$this->db->select('uid, nama, level');
		$login = $this->db->get_where('dn_users', $data);
		
		if($login->num_rows() > 0)
		{
			return $login->result();
		}
		
		return FALSE;
	}
	
	function get_alt_login($sid, $sc)
	{
		$this->db->select('u.uid, u.nama, u.level');
		$this->db->from('dn_users AS u');
		$this->db->join('dn_social AS s','u.uid=s.uid');
		$this->db->where('s.app', $sc);
		$this->db->where('s.sid', $sid);
		
		$login = $this->db->get();
		
		if($login->num_rows() > 0)
		{
			return $login->result();
		}
		
		return FALSE;
	}
	
	function get_email_user($email)
	{
		$this->db->select('email, sectoken');
		$this->db->where('email',$email);
		$login = $this->db->get('dn_users');
		
		if($login->num_rows() > 0){
			return $login->result();
		}
		
		return FALSE;
	}
	
	function set_user_token($email, $sectoken)
	{
		$data = array('sectoken' => $sectoken);
		
		$this->db->where('email', $email);
		$this->db->update('dn_users', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function set_user_password($data, $uid=0)
	{
		$this->db->where('uid', $uid);
		$this->db->update('dn_users', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function get_user_data($email, $sectoken)
	{
		$this->db->where('email', $email);
		$this->db->where('sectoken', $sectoken);
		
		$user = $this->db->get('dn_users');
		if($user->num_rows() > 0)
		{
			return $user->result();
		}
		
		return FALSE;
	}
	
	function set_user_daftar($data)
	{
		$this->db->insert('dn_users', $data);
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function set_user_verifikasi($email, $sectoken)
	{
		$data = array('status' => '1');
		
		$this->db->where('email', $email);
		$this->db->where('sectoken', $sectoken);
		
		$this->db->update('dn_users', $data);
		
		if($this->db->affected_rows() > 0)
		{
			return TRUE;
		}
		
		return FALSE;
	}
	
	function cek_user_name($username)
	{
		$this->db->where('username', $username);
		$this->db->get('dn_users');
		
		if($this->db->num_rows() > 0)
		{
			return FALSE;
		}
		
		return TRUE;
	}
	
	function cek_user_verifikasi($email)
	{
		$this->db->select('uid, nama, sectoken, status')->from('dn_users');
		$this->db->where('email', $email);
		
		$data = $this->db->get();
		
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function hitung_data($field,$table)
	{
		$this->db->select($field);
		$hitung = $this->db->get($table);
		
		return $hitung->num_rows();
	}
	
	function get_single_data($select,$table,$fid,$id)
	{
		$this->db->select($select);
		$this->db->from($table);
		$this->db->where($fid,$id);
		$data = $this->db->get();
		
		if($data->num_rows() > 0)
		{
			foreach($data->result() AS $hasil)
			{
				return $hasil->$select;
			}
		}
		
		return FALSE;
	}
	
	function get_daftar_kategori($awal=0, $order='asc')
	{
		$this->db->order_by('kategori', $order);
		$this->db->limit(20, $awal);
		$kategori = $this->db->get('dn_category');
		
		if($kategori->num_rows() > 0)
		{
			return $kategori;
		}
		
		return FALSE;
	}
	
	function get_daftar_perusahaan($awal=0, $order)
	{
		
		$this->db->select('idperusahaan,nama');
		$this->db->order_by('idperusahaan',$order);
		$this->db->limit(10,$awal);
		$perusahaan = $this->db->get('dn_company');
		
		if($perusahaan->num_rows() > 0)
		{
			return $perusahaan->result();
		}
		
		return FALSE;
	}
	
	function get_daftar_perusahaan_abj($awal=0, $order)
	{
		
		$this->db->select('idperusahaan,nama');
		$this->db->order_by('nama',$order);
		$this->db->limit(10,$awal);
		$perusahaan = $this->db->get('dn_company');
		
		if($perusahaan->num_rows() > 0)
		{
			return $perusahaan->result();
		}
		
		return FALSE;
	}
	
	function get_daftar_perusahaan_cat($awal=0, $cat=0)
	{
		
		$this->db->select('idperusahaan,nama');
		$this->db->where('idkategori', $cat);
		$this->db->order_by('idperusahaan','desc');
		$this->db->limit(10,$awal);
		$perusahaan = $this->db->get('dn_company');
		
		if($perusahaan->num_rows() > 0)
		{
			return $perusahaan->result();
		}
		
		return FALSE;
	}
	
	function get_data_perusahaan($idc=0)
	{
		$this->db->where('idperusahaan',$idc);
		$usaha = $this->db->get('dn_company');
		
		if($usaha->num_rows() > 0)
		{
			return $usaha->result();
		}
		
		return FALSE;
	}
	
	function hitung_perusahaan_per_kategori($kat=0)
	{
		$this->db->select('idperusahaan')->from('dn_company')->where('idkategori', $kat);
		$hitung = $this->db->get();
		
		return $hitung->num_rows();
	}
	
	function get_daftar_produk($awal=0, $order)
	{
		$this->db->select('idproduk,nama');
		$this->db->order_by('idproduk',$order);
		$this->db->limit(20,$awal);
		$produk = $this->db->get('dn_product');
		
		if($produk->num_rows() > 0)
		{
			return $produk->result();
		}
		
		return FALSE;
	}
	
	function get_daftar_produk_abj($awal=0, $order)
	{
		$this->db->select('idproduk,nama');
		$this->db->order_by('nama',$order);
		$this->db->limit(20,$awal);
		$produk = $this->db->get('dn_product');
		
		if($produk->num_rows() > 0)
		{
			return $produk->result();
		}
		
		return FALSE;
	}
	
	function get_data_produk($idp=0)
	{
		$this->db->where('idproduk',$idp);
		$produk = $this->db->get('dn_product');
		
		if($produk->num_rows() > 0)
		{
			return $produk->result();
		}
		
		return FALSE;
	}
	
	function get_produk_usaha($awal=0, $idc=0)
	{
		$this->db->select('idproduk,nama');
		$this->db->where('idperusahaan',$idc);
		$this->db->order_by('idproduk','desc');
		$this->db->limit(20, $awal);
		$produk = $this->db->get('dn_product');
		
		if($produk->num_rows() > 0)
		{
			return $produk->result();
		}
		
		return FALSE;
	}
	
	function get_hitung_produk_usaha($idc=0)
	{
		$this->db->select('idproduk');
		$this->db->where('idperusahaan',$idc);
		$this->db->order_by('idproduk','desc');
		
		$produk = $this->db->get('dn_product');
		
		return $produk->num_rows();
	}
	
	function get_daftar_produk_kategori($awal=0, $cat=0)
	{
		
		$this->db->select('p.idproduk AS idproduk, p.nama AS nama');
		$this->db->from('dn_product AS p');
		$this->db->join('dn_company AS c', 'p.idperusahaan=c.idperusahaan');
		$this->db->where('c.idkategori', $cat);
		$this->db->order_by('p.idproduk','desc');
		$this->db->limit(10, $awal);
		$perusahaan = $this->db->get();
		
		if($perusahaan->num_rows() > 0)
		{
			return $perusahaan->result();
		}
		
		return FALSE;
	}
	
	function get_hitung_produk_kategori($cat=0)
	{
		
		$this->db->select('p.idproduk');
		$this->db->from('dn_product AS p');
		$this->db->join('dn_company AS c', 'p.idperusahaan=c.idperusahaan');
		$this->db->where('c.idkategori', $cat);
		$this->db->order_by('p.idproduk','desc');
		
		$perusahaan = $this->db->get();
		
		return $perusahaan->num_rows();
	}
	
	function get_lowongan($awal=0)
	{
		$sekarang = date("Y-m-d");
		$this->db->select('idjob,idperusahaan,posisi');
		$this->db->where('berakhir >=',$sekarang);
		$this->db->limit(10,$awal);
		$lowongan = $this->db->get('dn_job');
		
		if($lowongan->num_rows() > 0)
		{
			return $lowongan->result();
		}
		
		return FALSE;
	}
	
	function get_hitung_lowongan()
	{
		$sekarang = date("Y-m-d");
		$this->db->select('idjob');
		$this->db->where('berakhir >=',$sekarang);
		
		$lowongan = $this->db->get('dn_job');
		
		
		return $lowongan->num_rows();
	}
	
	function get_lowongan_perusahaan($idc=0, $awal=0)
	{
		$sekarang = date("Y-m-d");
		$this->db->select('idjob,idperusahaan,posisi');
		$this->db->where('idperusahaan',$idc);
		$this->db->where('berakhir >=',$sekarang);
		$this->db->limit(10,$awal);
		$lowongan = $this->db->get('dn_job');
		
		if($lowongan->num_rows() > 0)
		{
			return $lowongan->result();
		}
		
		return FALSE;
	}
	
	function get_hitung_lowongan_perusahaan($idc=0)
	{
		$sekarang = date("Y-m-d");
		$this->db->select('idjob');
		$this->db->where('idperusahaan', $idc);
		$this->db->where('berakhir >=', $sekarang);
		
		$lowongan = $this->db->get('dn_job');
		
		return $lowongan->num_rows();
	}
	
	function get_data_lowongan($idc=0)
	{
		$this->db->where('idjob',$idc);
		$lowongan = $this->db->get('dn_job');
		
		if($lowongan->result() > 0)
		{
			return $lowongan->result();
		}
		
		return FALSE;
	}
	
	function get_daftar_acara($awal=0)
	{
		$hariini = date("Y-m-d");
		
		$this->db->select('idacara,nama');
		$this->db->where('tanggal >= ',$hariini);
		$this->db->order_by('idacara','desc');
		$this->db->limit(10, $awal);
		$query = $this->db->get('dn_event');
		
		if($query->num_rows() > 0)
		{
			return $query;
		}
		return FALSE;
	}
	
	function get_data_acara($ida=0)
	{
		
		$this->db->where('idacara', $ida);
		
		$query = $this->db->get('dn_event');	
		if($query->num_rows() > 0)
		{
			return $query->result();
		}
		return FALSE;
	}
	
	function get_user_info($uid)
	{
		$this->db->select('nama, email, jk, tglreg, gambar')->from('dn_users')->where('uid',$uid);
		$data = $this->db->get();
		if($data->num_rows() > 0)
		{
			return $data->result();
		}
		
		return FALSE;
	}
	
	function get_usaha_terbaru()
	{
		$this->db->select('idperusahaan, nama, deskripsi, logo')->from('dn_company')->where('logo != ""')->where('status', 1)->order_by('idperusahaan', 'desc')->limit(5, 0);
		$hasil = $this->db->get();
		if($hasil->num_rows() > 0)
		{
			return $hasil->result();
		}
		
		return FALSE;
	}
	
	function get_produk_terbaru()
	{
		$this->db->select('p.idproduk AS idproduk, p.nama AS nama, p.deskripsi AS deskripsi, p.gambar AS gambar')->from('dn_product AS p')->join('dn_company AS c', 'p.idperusahaan=c.idperusahaan')->where('c.status', 1)->order_by('p.idproduk', 'desc')->limit(5,0);
		$hasil = $this->db->get();
		if($hasil->num_rows() > 0)
		{
			return $hasil->result();
		}
		return FALSE;
	}
	
	function get_loker_terbaru()
	{
		$hariini = date("Y-m-d");
		
		$this->db->select('j.idjob AS idjob, j.posisi AS posisi, j.deskripsi AS deskripsi')->from('dn_job AS j')->join('dn_company AS c', 'j.idperusahaan=c.idperusahaan')->where('j.berakhir >=', $hariini)->where('c.status', 1)->order_by('j.idjob', 'desc')->limit(5,0);
		$hasil = $this->db->get();
		
		if($hasil->num_rows() > 0)
		{
			return $hasil->result();
		}
		
		return FALSE;
	}
	
	function get_acara_terbaru()
	{
		$hariini = date("Y-m-d");
		
		$this->db->select('*')->from('dn_event')->where('tanggal >=', $hariini)->order_by('idacara', 'desc')->limit(5,0);
		$hasil = $this->db->get();
		
		if($hasil->num_rows() > 0)
		{
			return $hasil->result();
		}
		
		return FALSE;
	}
	
	function get_latest($table)
	{
		$this->db->from($table);
		$this->db->order_by('(1)','desc');
		$this->db->limit(5);
		$query = $this->db->get();
		if($query->num_rows() > 0)
		{
			return $query->result();
		}
		
		return false;
	}
	
	function get_cari($cari,$awal=0){
		$this->db->select('pd.idproduk AS idproduk, pd.nama AS namaproduk, pd.deskripsi AS deskripsiproduk,cp.idperusahaan AS idperusahaan, cp.nama AS namaperusahaan, cp.pemilik AS pemilikusaha, cp.alamat AS alamatusaha, cp.kota AS kota, lw.idjob AS idlowongan, lw.posisi AS judullowongan,lw.deskripsi AS deskripsilowongan');
		$this->db->from('dn_company AS cp');
		$this->db->join('dn_product AS pd', 'cp.idperusahaan = pd.idperusahaan');
		$this->db->join('dn_job AS lw', 'cp.idperusahaan = lw.idperusahaan');
		
		$this->db->like('pd.nama', $cari);
		$this->db->or_like('pd.deskripsi', $cari);
		$this->db->or_like('cp.nama', $cari);  
		$this->db->or_like('cp.pemilik', $cari); 
		$this->db->or_like('cp.alamat', $cari);
		$this->db->or_like('cp.kota', $cari);  
		$this->db->or_like('lw.posisi', $cari); 
		$this->db->or_like('lw.deskripsi', $cari); 
		
		$this->db->limit(5, $awal);
		
		$query = $this->db->get();
		
		if($query->num_rows() > 0)
		{
			return $query;
		}
		
		return FALSE;
	}
	
	function get_cari_produk($cari, $awal)
	{
		$this->db->select('*');
		$this->db->from('dn_product');
		
		$this->db->like('nama', $cari);
		$this->db->or_like('deskripsi', $cari);
		
		$this->db->limit(10, $awal);
		
		$query = $this->db->get();
		
		if($query->num_rows() > 0)
		{
			return $query;
		}
		
		return FALSE;
	}
	
	function get_hitung_cari_produk($cari)
	{
		$this->db->select('*');
		$this->db->from('dn_product');
		
		$this->db->like('nama', $cari);
		$this->db->or_like('deskripsi', $cari);
		
		$query = $this->db->get();
		
		return $query->num_rows();
	}
	
	function get_cari_perusahaan($cari, $awal)
	{
		$this->db->select('*');
		$this->db->from('dn_company');
		
		$this->db->like('nama', $cari);
		$this->db->or_like('pemilik', $cari);
		$this->db->or_like('deskripsi', $cari);
		$this->db->or_like('alamat', $cari);
		$this->db->or_like('kota', $cari);
		
		$this->db->limit(10, $awal);
		
		$query = $this->db->get();
		
		if($query->num_rows() > 0)
		{
			return $query;
		}
		
		return FALSE;
	}
	
	function get_hitung_cari_perusahaan($cari)
	{
		$this->db->select('*');
		$this->db->from('dn_company');
		
		$this->db->like('nama', $cari);
		$this->db->or_like('pemilik', $cari);
		$this->db->or_like('deskripsi', $cari);
		$this->db->or_like('alamat', $cari);
		$this->db->or_like('kota', $cari);
		
		$query = $this->db->get();
		
		
		return $query->num_rows() ;
	}
	
	function get_cari_acara($cari, $awal)
	{
		$this->db->select('*');
		$this->db->from('dn_event');
		
		$this->db->like('nama', $cari);
		$this->db->or_like('deskripsi', $cari);
		$this->db->or_like('lokasi', $cari);
		
		$this->db->limit(10, $awal);
		
		$query = $this->db->get();
		
		if($query->num_rows() > 0)
		{
			return $query;
		}
		
		return FALSE;
	}
	
	function get_hitung_cari_acara($cari)
	{
		$this->db->select('*');
		$this->db->from('dn_event');
		
		$this->db->like('nama', $cari);
		$this->db->or_like('deskripsi', $cari);
		$this->db->or_like('lokasi', $cari);
		
		$query = $this->db->get();
		
		return $query->num_rows();
	}
	
	function get_cari_loker($cari, $awal)
	{
		$this->db->select('*');
		$this->db->from('dn_job');
		
		$this->db->like('posisi', $cari);
		$this->db->or_like('deskripsi', $cari);
		$this->db->or_like('lokasi', $cari);
		
		$this->db->limit(10, $awal);
		
		$query = $this->db->get();
		
		if($query->num_rows() > 0)
		{
			return $query;
		}
		
		return FALSE;
	}
	
	function get_hitung_cari_loker($cari)
	{
		$this->db->select('*');
		$this->db->from('dn_job');
		
		$this->db->like('posisi', $cari);
		$this->db->or_like('deskripsi', $cari);
		$this->db->or_like('lokasi', $cari);
		
		$query = $this->db->get();
		
		return $query->num_rows();
	}
	
	function get_bantuan($apa, $tipe)
	{
		$this->db->where('idbantuan', $apa);
		$this->db->where('tipe', $tipe);
		
		$query = $this->db->get('dn_help');
		if($query->num_rows() > 0)
		{
			return $query->result();
		}
		
		return FALSE;
	}
    
}

/* End of file main_model.php */
/* Location: ./application/models/main_model.php */
